<%@page import="com.glowdayz.glowmee.dao.RegisterDAO"%>
<%@page import="com.glowdayz.glowmee.cmd.RegisterCMD"%>
<%@ page language="java" contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@page import="com.glowdayz.common.DBHandler"%>
<%@page import="com.glowdayz.common.ApiHandler"%>
<%@page import="com.glowdayz.common.ApiHandler.XmlData"%>
<%@page import="java.util.ArrayList"%>
<%
	DBHandler.getInstance().connect();

	ApiHandler web = new ApiHandler(request, out, "JSPglowmee");
	
	int id = web.getInt("id");
	String beforePw = web.getValue("beforePw");
	String newPw = web.getValue("newPw");
	
	int insert = 0;
	
	int count = DBHandler.getInstance().getCount("register", "*", "idRegister=" + id + " AND passWord=password('" + beforePw + "')");
	if (count < 1) {
		DBHandler.getInstance().disconnect();
		web.result(null, "현재 비밀번호 정보가 올바르지 않습니다.");
		return;
	}
	
	RegisterCMD cmd = new RegisterCMD(id, newPw);
	insert = RegisterDAO.getInstance().updateRegisterPassword(cmd);
	
	if (insert < 1) {
		DBHandler.getInstance().disconnect();
		web.result(null, "변경에 실패하였습니다.");
		return;
	}
	
	DBHandler.getInstance().disconnect();
	
	ArrayList<XmlData> list = new ArrayList<XmlData>();
	list.add(new XmlData("seq", insert));
	web.result("SUCCESS", "비밀번호가 정상적으로 변경되었습니다.", list);
%>